package org.paychina.demo;

import java.util.regex.Pattern;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.storage.StorageLevel;

public class CountActor {

	public static final String ANALYZE = "src/main/resources/CountActor.txt";
	private static final Pattern SPACE = Pattern.compile(" ");
	//
	public static void main(String[] args) {
		
		//Spark配置
		SparkConf sparkConf = new SparkConf();
		sparkConf.set("spark.app.name", "CountActor");
		sparkConf.set("spark.master", "local[1]");
		sparkConf.set("spark.ui.port", "36000"); //# 重载默认端口配置

		JavaSparkContext ctx = new JavaSparkContext(sparkConf);
		JavaRDD<String> lines = ctx.textFile(ANALYZE, 1);
		
		Long lineCount = lines.count();
		
		System.out.println("该文件一共有"+lineCount+"行");
		
		String firstContent = lines.first();
		
		System.out.println("第一行的内容:"+firstContent);
		
		//缓存到内存和磁盘中
		lines.persist(StorageLevel.MEMORY_AND_DISK());
	}
}
